package com.jshare.action;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import com.jshare.entity.TzReply;
import com.jshare.service.TieziService;
import com.jshare.tiezi.use.LanTranfer;
import com.jshare.tiezi.use.TieziToUse;
import com.jshare.tiezi.use.fenye.PageInfo;
import com.opensymphony.xwork2.ActionSupport;

public class TzReplyAction extends ActionSupport {
	// 帖子 相关操作的 service
	@Resource(name = "tieziService")
	private TieziService tieziService;
	// 将 页面传过来的参数 封装成 对象
	@Resource(name = "tieziToUseService")
	private TieziToUse tiziToUseService;

	private int tiezi_id;
	private String replyer;
	private String content;
	private int curPage = 1;
	private int pageSize = 1;
	private int pageCount = 1;
	private String locate;
	private String replyer_add;
	private List tieandrels = new ArrayList();
	
	
	public String getLocate() {
		return locate;
	}

	public void setLocate(String locate) {
		this.locate = locate;
	}

	public String getReplyer_add() {
		return replyer_add;
	}

	public void setReplyer_add(String replyer_add) {
		this.replyer_add = replyer_add;
	}

	public int getPageCount() {
		return pageCount;
	}

	public void setPageCount(int pageCount) {
		this.pageCount = pageCount;
	}

	public List getTieandrels() {
		return tieandrels;
	}

	public void setTieandrels(List tieandrels) {
		this.tieandrels = tieandrels;
	}

	public int getCurPage() {
		return curPage;
	}

	public void setCurPage(int curPage) {
		this.curPage = curPage;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public TieziService getTieziService() {
		return tieziService;
	}

	public void setTieziService(TieziService tieziService) {
		this.tieziService = tieziService;
	}

	public TieziToUse getTiziToUseService() {
		return tiziToUseService;
	}

	public void setTiziToUseService(TieziToUse tiziToUseService) {
		this.tiziToUseService = tiziToUseService;
	}

	public int getTiezi_id() {
		return tiezi_id;
	}

	public void setTiezi_id(int tiezi_id) {
		this.tiezi_id = tiezi_id;
	}

	public String getReplyer() {
		return replyer;
	}

	public void setReplyer(String replyer) {
		this.replyer = replyer;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}
	
	public String GetSingleTieAndReply(){
//		System.out.println("tiezi_id :"+tiezi_id);
//		System.out.println("curpage :"+curPage);
		Integer tieid = Integer.valueOf(tiezi_id);
		// 自己设置 size 为 每页显示的数量
		int size = 6;
		PageInfo info = tieziService.getSingleTieAndReply(curPage, size, tieid);
		setPageSize(info.getPageSize());
		setPageCount(info.getPageCount());
		setTieandrels(info.getResultlist());
		return SUCCESS;
	}
	
	public String addTzReply(){
		Integer mainTieziId = Integer.valueOf(tiezi_id);
		Integer locateid = Integer.valueOf(locate);
//		content = LanTranfer.tranfer(content);
//		String replyer = LanTranfer.tranfer(replyer_add);
		TzReply tr =  tiziToUseService.changetoRzReply(mainTieziId, replyer, content, locateid);
		tieziService.addTzReply(tr);
		return SUCCESS;
	}
}
